import { Crypto, Base64} from "./crypyo.js"

const app = getApp()
// let accessid='LTAI4Fps3ZKFauxBMeQrpTVE';
// let accesskey='Mbnbfx5jqeRp37QJXtqk4x6Weu9SLc';
// let host='https://oss-images.ywxktrip.com';
let {accessid,accesskey,host}= app.globalData.oss
// accessid;//你自己的阿里云的accessid
// accesskey;//你自己的阿里云的accesskey
// host//你自己的阿里云域名
const aliOssParams =function() {
    var policyText = {
      "expiration": "2052-01-01T12:00:00.000Z",//上传的文件失效日期自己定义
      "conditions": [
        ["content-length-range", 0, 1024*1024*1000]//上传的内容大小，自己定义
      ]
    };
    var policy = Base64.encode(JSON.stringify(policyText));//生成的加密策略
    var bytes = Crypto.util.HMAC(Crypto.util.SHA1, policy, accesskey, { asBytes: true });
    var signature = Crypto.util.bytesToBase64(bytes);//生成的签名
    return {
      policy: policy,
      signature: signature,
      aid: accessid,
      host: host//你自己的阿里云域名
    }
  }
 
 
export { aliOssParams };